package com.lvy.hczn.front.business.controller;

import com.lvy.hczn.front.business.service.GoodsBoxDetailService;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.core.page.TableDataInfo;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.system.domain.business.GoodsBox;
import com.lvy.hczn.front.system.domain.business.GoodsBoxDetail;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/wcs/box/detailInfo/")
@Slf4j
public class GoodsBoxDetainInfoController extends BaseController {

    @Autowired
    private GoodsBoxDetailService goodsBoxDetailService;

    private String prefix = "system/boxdetail";

    @RequiresPermissions("system:box:detail:view")
    @GetMapping("detail")
    public String detail() {
        return prefix + "/detail";
    }

    /**
     * 查询货箱详情列表
     */
    @RequiresPermissions("system:box:detail:list")
    @PostMapping("list")
    @ResponseBody
    public TableDataInfo list(GoodsBoxDetail goodsBoxDetail) {
        startPage();
        List<GoodsBoxDetail> list = goodsBoxDetailService.selectGoodsBoxDetailList(goodsBoxDetail);
        return getDataTable(list);
    }

    /**
     * 导出货箱详情列表
     */
    @RequiresPermissions("system:box:detail:export")
    @Log(title = "货箱详情", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    @ResponseBody
    public AjaxResult export(GoodsBoxDetail goodsBoxDetail) {
        List<GoodsBoxDetail> list = goodsBoxDetailService.selectGoodsBoxDetailList(goodsBoxDetail);
        ExcelUtil<GoodsBoxDetail> util = new ExcelUtil<GoodsBoxDetail>(GoodsBoxDetail.class);
        return util.exportExcel(list, "货箱详情数据");
    }

    /**
     * 新增货箱详情
     */
    @GetMapping("add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存货箱详情
     */
    @RequiresPermissions("system:box:detail:add")
    @Log(title = "货箱详情", businessType = BusinessType.INSERT)
    @PostMapping("add")
    @ResponseBody
    public AjaxResult addSave(GoodsBoxDetail goodsBoxDetail) {
        return toAjax(goodsBoxDetailService.insertGoodsBoxDetail(goodsBoxDetail));
    }

    /**
     * 修改货箱详情
     */
    @RequiresPermissions("system:box:detail:edit")
    @GetMapping("edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        GoodsBoxDetail goodsBoxDetail = goodsBoxDetailService.selectGoodsBoxDetailById(id);
        mmap.put("goodsBoxDetail", goodsBoxDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存货箱详情
     */
    @RequiresPermissions("system:box:detail:edit")
    @Log(title = "货箱详情", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    @ResponseBody
    public AjaxResult editSave(GoodsBoxDetail goodsBoxDetail) {
        return toAjax(goodsBoxDetailService.updateGoodsBoxDetail(goodsBoxDetail));
    }

    /**
     * 删除货箱详情
     */
    @RequiresPermissions("system:box:detail:remove")
    @Log(title = "货箱详情", businessType = BusinessType.DELETE)
    @PostMapping("remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(goodsBoxDetailService.deleteGoodsBoxDetailByIds(ids));
    }

    /**
     * 新增货箱详情
     */
    @GetMapping("bigProductEntryPage")
    public String bigProductEntryOpen(HttpServletRequest request, String ids, ModelMap mmap) {
        goodsBoxDetailService.bigProductEntryOpen(request, ids, mmap);
        return prefix + "/bigProductEntry";
    }

    /**
     * 大件商品入货架
     */
    @RequiresPermissions("system:box:detail:edit")
    @Log(title = "大件商品入货架", businessType = BusinessType.INSERT)
    @PostMapping("bigProductEntry")
    @ResponseBody
    public AjaxResult bigProductEntry(GoodsBox goodsBox) {
        goodsBoxDetailService.bigProductEntry((goodsBox));
        return toAjax(1);
    }
}
